package com.hasity.controller;


import com.hasity.common.resp.Result;
import com.hasity.dto.EbookDto;
import com.hasity.dto.EbookSaveDto;
import com.hasity.service.IEbookService;
import com.hasity.vo.EbookVo;
import com.hasity.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 电子书 前端控制器
 * </p>
 *
 * @author zjw
 * @since 2023-10-31
 */
@RestController
@RequestMapping("/ebook")
public class EbookController {
    @Autowired
    private IEbookService ebookService;

    @GetMapping("list")
    public Result<PageVo<EbookVo>> list(@Valid EbookDto req) {
        PageVo<EbookVo> list = ebookService.list(req);
        return Result.success(list);
    }
    @PostMapping("/save")
    public Result save(@Valid @RequestBody EbookSaveDto req) {
        ebookService.save(req);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        ebookService.delete(id);
        return Result.success();
    }
}
